package com.zrx.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zrx.domain.ResponseResult;
import com.zrx.domain.dto.EditTagDto;
import com.zrx.domain.dto.TagListDto;
import com.zrx.domain.entity.Tag;
import com.zrx.domain.vo.PageVo;
import com.zrx.service.TagService;
import com.zrx.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张荣欣
 * @create ：2022/9/26  10:11
 */
@RestController
@RequestMapping("/content/tag")
@Api(tags = "标签")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping("/list")
    @ApiOperation(value = "查询分页标签", notes = "查询分页标签")
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, TagListDto tagListDto){
        return tagService.pageTagList(pageNum,pageSize,tagListDto);
    }

    @PostMapping()
    @ApiOperation(value = "新增标签", notes = "新增标签")
    public ResponseResult addTag(@RequestBody Tag tag){
        tagService.save(tag);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "刪除标签", notes = "刪除标签")
    public ResponseResult deleteTag(@PathVariable("id") List<Long> ids){
        tagService.removeByIds(ids);
        return ResponseResult.okResult();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取标签", notes = "根据id获取标签")
    public ResponseResult getByIdOneTag(@PathVariable("id") Long id){

        return ResponseResult.okResult(tagService.getById(id));
    }

    @PutMapping()
    @ApiOperation(value = "修改标签", notes = "修改标签")
    public ResponseResult updateTag(@RequestBody EditTagDto tagDto){
        Tag tag = BeanCopyUtils.copyBean(tagDto,Tag.class);
        tagService.updateById(tag);
        return ResponseResult.okResult();
    }

    @GetMapping("/listAllTag")
    @ApiOperation(value = "查询所有标签", notes = "查询所有标签")
    public ResponseResult listAllTag(){
        return tagService.listAlltag();
    }


}
